﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DBModel;
using ZSDDBHelper;
namespace BllService
{
    public class SysBasicService : DbCommon
    {
        #region MyRegion
        public string getDevice(Map_Device model)
        {
            List<Map_Device> listResult = new List<Map_Device>();
            try
            {
                SearchSQLModel searchModel = new SearchSQLModel();
                searchModel.MainTable = SYS_Table.Map_Device.ToString();

                if (!string.IsNullOrEmpty(model.ID))
                    searchModel.FilterCondition += "AND( ID= '" + model.ID + "')";

                listResult = SearchData<Map_Device>(searchModel);

                return SerializeToResultModel(listResult);
            }
            catch (Exception ex)
            {
                Utility.LogHelper.InstanctLogHelper.WriteLog(ex.Message);
                return SerializeObject(new ResultModel { code = -1, msg = ex.Message, data = null, });
            }
        }

        public string AddDevice(Map_Device model)
        {
            if (string.IsNullOrEmpty(model.ID))
            {
                model.ID = Utility.GuidFormat.NewGuidN;
                result = base.InserTable(SYS_Table.Map_Device.ToString(), model);
                if (result.code == 1)
                {
                    result.msg = model.ID;
                }
                else
                    result.msg = "";
            }
            else
            {
                result = base.UpdateTableByKey(SYS_Table.Map_Device.ToString(), model);
            }
            return base.SerializeObject(result);
        }

        public string getDeviceSelect()
        {
            List<SelectModel> listResult = new List<SelectModel>();
            try
            {
                SearchSQLModel searchModel = new SearchSQLModel();
                searchModel.MainTable = SYS_Table.Map_Device.ToString();
                searchModel.SearchColumns = new string[] { SYS_Table.Map_Device.ToString() + ".ID CODE," + SYS_Table.Map_Device.ToString() + ".Name NAME" };
                //searchModel.FilterCondition += "AND( longitude ='' OR longitude IS NULL )";

                listResult = SearchData<SelectModel>(searchModel);

                return SerializeToResultModel(listResult);
            }
            catch (Exception ex)
            {
                Utility.LogHelper.InstanctLogHelper.WriteLog(ex.Message);
                return SerializeObject(new ResultModel { code = -1, msg = ex.Message, data = null, });
            }
        }
        #endregion
    }
}
